package designMode.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description  具体文件夹类，可以添加文件夹和子文件夹
 * @Author 肖地洋
 * @Date 2022/8/18 16:30
 */
public class Folder extends Root{
    private List<Root> folders = new ArrayList<Root>();

    public List<Root> getRoot() {
        return folders;
    }

    public void setRoot(List<Root> folders) {
        this.folders = folders;
    }

    public Folder(String name) {
        super(name);
    }

    @Override
    public void addFile(Root root) {
        folders.add(root);
    }

    @Override
    public void removeFile(Root root) {
        folders.remove(root);
    }

    @Override
    public void display(int depth) {
        StringBuilder sb = new StringBuilder();
        for (int i=0;i<depth;i++){
            sb.append("-");
        }
        //打印横线和当前文件名
        System.out.println(sb.toString()+this.getName());
        for(Root r:folders){
            r.display(depth+2);
        }
    }
}
